package cn.tqfeiyang.springplus;

import cn.tqfeiyang.springplus.framework.security.AuthenticationUserDetails;
import cn.tqfeiyang.springplus.framework.security.AuthenticationUserLoader;
import cn.tqfeiyang.springplus.framework.security.JwtTokenService;
import cn.tqfeiyang.springplus.framework.toolkit.ContextUtils;
import cn.tqfeiyang.springplus.system.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.ArrayList;
import java.util.UUID;
import java.util.List;

@SpringBootApplication
public class Application implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Resource
    private AuthenticationUserLoader authenticationUserLoader;

    @Resource
    private JwtTokenService jwtTokenService;

    @Resource
    private PasswordEncoder passwordEncoder;

    @Resource
    private UserService userService;

    @Override
    public void run(String... args) throws Exception {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));

        System.out.println("AuthenticationUserLoader.class = " + authenticationUserLoader.getClass().getCanonicalName());
        AuthenticationUserDetails userDetails = authenticationUserLoader.loadByUsername("admin");
        System.out.println(jwtTokenService.build(userDetails));

        System.out.println("pass(123456): " + passwordEncoder.encode("123456"));
        System.out.println("uuid: " + UUID.randomUUID().toString());

        ContextUtils.getBeansOfType(AuthenticationUserLoader.class).forEach(System.out::println);

        //userService.selectRoles(1L);

//        List<Long> roleIds = new ArrayList<>();
//        roleIds.add(1L);
////        roleIds.add(2L);
////        roleIds.add(3L);
//        userService.assignRoleIds(2L, roleIds);
    }
}
